<template>
    <div class="login">
        <div class="login-wrapper">
          <h2 class="login-title">登录</h2>
          <div class="login-cont">
            <div class="login-box margin-b40">
              <img src="../../../../assets/img/icon_phone.png" class="iconimg">
              <yd-input slot="right" v-model="phone" regex="mobile" placeholder="请输入手机号码" class="phone"></yd-input>
            </div>
            <div class="login-box margin-b20">
               <img src="../../../../assets/img/icon_password.png" class="iconimg">
              <yd-input slot="right" type="password" v-model="password" placeholder="请输入密码" class="password"></yd-input>
            </div>
            <div class="login-jump">
              <div class="jump-password" @click="jumppassword()">忘记密码</div>
            </div>
            <div class="login-btn" @click="login()">登&nbsp;录</div>
            <div class="login-jump">
              <div class="jump-sgin">
                <div class="jump-sgin-rack">
                  没有账号
                </div>
                <div class="jump-sgin-btn" @click="jumpsgin()">
                  立刻注册
                </div>
              </div>
            </div>
          </div>
        </div>
    </div>
</template>

<script>
import apis from '../../../../../static/js/apis.js'
import {setToken} from '../../../../../static/js/auth'
export default {
  components: {
    apis
  },
  data () {
    return {
      phone: '',
      password: '',
      userInfo: {}
    }
  },
  methods: {
    login () {
      if (this.phone === '' && this.phone.length !== 11) {
        this.$dialog.alert({mes: '请输入正确的手机号!'})
      } else if (this.password === '') {
        this.$dialog.alert({mes: '请输入密码!'})
      } else {
        let qs = require('querystring')
        this.$axios.post(apis + '/auth/messagep',
          qs.stringify({
            username: this.phone,
            code: this.code,
            password: this.password
          })
        )
          .then(response => {
            console.log(response)
            if (response.data !== 'ERROR') {
              setToken(response.data.token, 3)
              this.userInfo = response.data
              window.localStorage.setItem('userInfo', JSON.stringify(this.userInfo))
              this.$router.push({
                path: '/index'
              })
            } else {
              this.$dialog.alert({mes: '手机号或密码错误!'})
            }
          })
          .catch(error => {
            console.log(error)
          })
      }
    },
    jumppassword () {
      this.$router.push({
        path: '/ForgetPassword'
      })
    },
    jumpsgin () {
      this.$router.push({
        path: '/sign'
      })
    }
  }
}
</script>

<style scoped>
.login{
position: fixed;
top:0;
bottom: 0;
width: 100%;
background: #fff;
}
.login-title{
  font-size: 24px;
  font-weight: bold;
  padding:0 40px;
  margin:145px 0;
}
.login-cont{
  overflow: hidden;
  padding: 0 40px;
}
.login-box{
  width: 100%;
  display: flex;
  height: 40px;
  border-bottom: 1px solid #c4c4c4;
}
.phone{
flex:1;
font-size: 14px;
}
.iconimg{
  width: 15px;
  height: 20px;
  margin-right: 10px;
  margin-top: 10px;
}
.pssword{
  flex:1;
  font-size: 14px;
}
.margin-b40{
  margin-bottom: 40px;
}
.margin-b20{
  margin-bottom: 20px;
}
.login-jump{
  width: 100%;
  margin-bottom: 88px;
}
.jump-password{
  text-align: right;
  font-size:12px;
  color:#999;
}
.login-btn{
  width: 100%;
  border-radius: 10px;
  background: #ffd602;
  color:#fff;
  font-size: 15px;
  font-weight: bold;
  height: 40px;
  line-height: 40px;
  text-align: center;
  margin-bottom: 25px;
}
.jump-sgin{
  display: flex;
}
.jump-sgin-rack{
  flex:1;
  text-align: right;
  font-size: 14px;
  color:#666;
  margin-right: 5px;
}
.jump-sgin-btn{
  flex:1;
  text-align: left;
  font-size: 14px;
  color:#ffd602;
  margin-left: 5px;
}
</style>
